home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / jce.jar / javax / crypto / EncryptedPrivateKeyInfo.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-07-27  |  5.0 KB  |  222 lines

  1. package javax.crypto;
  2.  
  3. import java.io.IOException;
  4. import java.security.AlgorithmParameters;
  5. import java.security.GeneralSecurityException;
  6. import java.security.InvalidKeyException;
  7. import java.security.Key;
  8. import java.security.NoSuchAlgorithmException;
  9. import java.security.NoSuchProviderException;
  10. import java.security.Provider;
  11. import java.security.Security;
  12. import java.security.spec.InvalidKeySpecException;
  13. import java.security.spec.PKCS8EncodedKeySpec;
  14. import sun.security.util.DerInputStream;
  15. import sun.security.util.DerOutputStream;
  16. import sun.security.util.DerValue;
  17. import sun.security.x509.AlgorithmId;
  18.  
  19. public class EncryptedPrivateKeyInfo {
  20.    // $FF: renamed from: a sun.security.x509.AlgorithmId
  21.    private AlgorithmId field_0;
  22.    // $FF: renamed from: b byte[]
  23.    private byte[] field_1;
  24.    // $FF: renamed from: c byte[]
  25.    private byte[] field_2 = null;
  26.  
  27.    public EncryptedPrivateKeyInfo(byte[] var1) throws IOException {
  28.       if (var1 == null) {
  29.          throw new NullPointerException("the encoded parameter must be non-null");
  30.       } else {
  31.          this.field_2 = (byte[])var1.clone();
  32.          DerValue var2 = new DerValue(this.field_2);
  33.          DerValue[] var3 = new DerValue[]{var2.data.getDerValue(), var2.data.getDerValue()};
  34.          if (var2.data.available() != 0) {
  35.             throw new IOException("overrun, bytes = " + var2.data.available());
  36.          } else {
  37.             this.field_0 = AlgorithmId.parse(var3[0]);
  38.             if (var3[0].data.available() != 0) {
  39.                throw new IOException("encryptionAlgorithm field overrun");
  40.             } else {
  41.                this.field_1 = var3[1].getOctetString();
  42.                if (var3[1].data.available() != 0) {
  43.                   throw new IOException("encryptedData field overrun");
  44.                }
  45.             }
  46.          }
  47.       }
  48.    }
  49.  
  50.    public EncryptedPrivateKeyInfo(String var1, byte[] var2) throws NoSuchAlgorithmException {
  51.       if (var1 == null) {
  52.          throw new NullPointerException("the algName parameter must be non-null");
  53.       } else {
  54.          this.field_0 = AlgorithmId.get(var1);
  55.          if (var2 == null) {
  56.             throw new NullPointerException("the encryptedData parameter must be non-null");
  57.          } else if (var2.length == 0) {
  58.             throw new IllegalArgumentException("the encryptedData parameter must not be empty");
  59.          } else {
  60.             this.field_1 = (byte[])var2.clone();
  61.             this.field_2 = null;
  62.          }
  63.       }
  64.    }
  65.  
  66.    public EncryptedPrivateKeyInfo(AlgorithmParameters var1, byte[] var2) throws NoSuchAlgorithmException {
  67.       if (var1 == null) {
  68.          throw new NullPointerException("algParams must be non-null");
  69.       } else {
  70.          this.field_0 = AlgorithmId.get(var1);
  71.          if (var2 == null) {
  72.             throw new NullPointerException("encryptedData must be non-null");
  73.          } else if (var2.length == 0) {
  74.             throw new IllegalArgumentException("the encryptedData parameter must not be empty");
  75.          } else {
  76.             this.field_1 = (byte[])var2.clone();
  77.             this.field_2 = null;
  78.          }
  79.       }
  80.    }
  81.  
  82.    public String getAlgName() {
  83.       return this.field_0.getName();
  84.    }
  85.  
  86.    public AlgorithmParameters getAlgParameters() {
  87.       return this.field_0.getParameters();
  88.    }
  89.  
  90.    public byte[] getEncryptedData() {
  91.       return (byte[])this.field_1.clone();
  92.    }
  93.  
  94.    public PKCS8EncodedKeySpec getKeySpec(Cipher var1) throws InvalidKeySpecException {
  95.       Object var2 = null;
  96.  
  97.       try {
  98.          var8 = var1.doFinal(this.field_1);
  99.          method_2(var8);
  100.       } catch (GeneralSecurityException var5) {
  101.          InvalidKeySpecException var10 = new InvalidKeySpecException("Cannot retrieve the PKCS8EncodedKeySpec");
  102.          var10.initCause(var5);
  103.          throw var10;
  104.       } catch (IOException var6) {
  105.          InvalidKeySpecException var9 = new InvalidKeySpecException("Cannot retrieve the PKCS8EncodedKeySpec");
  106.          var9.initCause(var6);
  107.          throw var9;
  108.       } catch (IllegalStateException var7) {
  109.          InvalidKeySpecException var4 = new InvalidKeySpecException("Cannot retrieve the PKCS8EncodedKeySpec");
  110.          var4.initCause(var7);
  111.          throw var4;
  112.       }
  113.  
  114.       return new PKCS8EncodedKeySpec(var8);
  115.    }
  116.  
  117.    // $FF: renamed from: a (java.security.Key, java.security.Provider) java.security.spec.PKCS8EncodedKeySpec
  118.    private PKCS8EncodedKeySpec method_0(Key var1, Provider var2) throws NoSuchAlgorithmException, InvalidKeyException {
  119.       Object var3 = null;
  120.  
  121.       try {
  122.          Cipher var4;
  123.          if (var2 == null) {
  124.             var4 = Cipher.getInstance(this.field_0.getName());
  125.          } else {
  126.             var4 = Cipher.getInstance(this.field_0.getName(), var2);
  127.          }
  128.  
  129.          var4.init(2, var1, this.field_0.getParameters());
  130.          var10 = var4.doFinal(this.field_1);
  131.          method_2(var10);
  132.       } catch (NoSuchAlgorithmException var7) {
  133.          throw var7;
  134.       } catch (GeneralSecurityException var8) {
  135.          InvalidKeyException var11 = new InvalidKeyException("Cannot retrieve the PKCS8EncodedKeySpec");
  136.          var11.initCause(var8);
  137.          throw var11;
  138.       } catch (IOException var9) {
  139.          InvalidKeyException var6 = new InvalidKeyException("Cannot retrieve the PKCS8EncodedKeySpec");
  140.          var6.initCause(var9);
  141.          throw var6;
  142.       }
  143.  
  144.       return new PKCS8EncodedKeySpec(var10);
  145.    }
  146.  
  147.    public PKCS8EncodedKeySpec getKeySpec(Key var1) throws NoSuchAlgorithmException, InvalidKeyException {
  148.       if (var1 == null) {
  149.          throw new NullPointerException("decryptKey is null");
  150.       } else {
  151.          return this.method_0(var1, (Provider)null);
  152.       }
  153.    }
  154.  
  155.    public PKCS8EncodedKeySpec getKeySpec(Key var1, String var2) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException {
  156.       if (var1 == null) {
  157.          throw new NullPointerException("decryptKey is null");
  158.       } else if (var2 == null) {
  159.          throw new NullPointerException("provider is null");
  160.       } else {
  161.          Provider var3 = Security.getProvider(var2);
  162.          if (var3 == null) {
  163.             throw new NoSuchProviderException("provider " + var2 + " not found");
  164.          } else {
  165.             return this.method_0(var1, var3);
  166.          }
  167.       }
  168.    }
  169.  
  170.    public PKCS8EncodedKeySpec getKeySpec(Key var1, Provider var2) throws NoSuchAlgorithmException, InvalidKeyException {
  171.       if (var1 == null) {
  172.          throw new NullPointerException("decryptKey is null");
  173.       } else if (var2 == null) {
  174.          throw new NullPointerException("provider is null");
  175.       } else {
  176.          return this.method_0(var1, var2);
  177.       }
  178.    }
  179.  
  180.    public byte[] getEncoded() throws IOException {
  181.       if (this.field_2 == null) {
  182.          DerOutputStream var1 = new DerOutputStream();
  183.          DerOutputStream var2 = new DerOutputStream();
  184.          this.field_0.encode(var2);
  185.          var2.putOctetString(this.field_1);
  186.          var1.write((byte)48, var2);
  187.          this.field_2 = var1.toByteArray();
  188.       }
  189.  
  190.       return (byte[])this.field_2.clone();
  191.    }
  192.  
  193.    // $FF: renamed from: a (sun.security.util.DerValue, byte, java.lang.String) void
  194.    private static void method_1(DerValue var0, byte var1, String var2) throws IOException {
  195.       if (var0.getTag() != var1) {
  196.          throw new IOException("invalid key encoding - wrong tag for " + var2);
  197.       }
  198.    }
  199.  
  200.    // $FF: renamed from: a (byte[]) void
  201.    private static void method_2(byte[] var0) throws IOException {
  202.       DerInputStream var1 = new DerInputStream(var0);
  203.       DerValue[] var2 = var1.getSequence(3);
  204.       switch (var2.length) {
  205.          case 4:
  206.             method_1(var2[3], (byte)-128, "attributes");
  207.          case 3:
  208.             method_1(var2[0], (byte)2, "version");
  209.             DerInputStream var3 = var2[1].toDerInputStream();
  210.             var3.getOID();
  211.             if (var3.available() != 0) {
  212.                var3.getDerValue();
  213.             }
  214.  
  215.             method_1(var2[2], (byte)4, "privateKey");
  216.             return;
  217.          default:
  218.             throw new IOException("invalid key encoding");
  219.       }
  220.    }
  221. }
  222.